package cn.dnui_jzy913.dnuifood_16110100913.Fragment;

import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;

import java.util.List;

import cn.dnui_jzy913.dnuifood_16110100913.Adapter.Fragment_shopAdapter;
import cn.dnui_jzy913.dnuifood_16110100913.R;
import cn.dnui_jzy913.dnuifood_16110100913.bean.UserCollection;
import cn.dnui_jzy913.dnuifood_16110100913.listener.RetrofitListener;
import cn.dnui_jzy913.dnuifood_16110100913.model.UserModel;

public class F2_FoodFragment extends BaseFragment implements RetrofitListener<List<UserCollection>> {
    private Fragment_shopAdapter adapter;
    private UserModel userModel;
    @Override
    protected int initlayout() {
        return R.layout.fragment2_sc_food;
    }
    @Override
    void initViews() {
        recyclerView = view.findViewById(R.id.rv_sc_food);  //1.获取列表元素
    }

    @Override
    void initData() {
        userModel = new UserModel();  //5.获取网络数据
        userModel.getAllUserCollection(getUser_id(),"1",this);
    }

    @Override
    void initEvents() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(//2.创建布局管理器
                getActivity(),
                LinearLayoutManager.VERTICAL,
                false
        );
        recyclerView.setLayoutManager(linearLayoutManager);//3.给recyclerview设置布局容器
        recyclerView.setItemAnimator(new DefaultItemAnimator());//4.设置动画效果
    }


    @Override
    public void onSuccess(List<UserCollection> object, int flag) {
        adapter = new Fragment_shopAdapter(getActivity(),object,R.layout.sc_food_item,getUser_id());  //6.设置数据
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void onFalure() {
        showToast("网络错误");
    }
}